package com.eling.elcms.community.model;

import com.eling.elcms.basedoc.model.AdministrativeDivision;
import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.privilege.model.User;
import com.eling.elcms.system.model.OrganizationBusinessType;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * 机构
 * 
 * @author KEN
 * 
 */
@Entity
@Table(name = "cm_organization")
@Indexed
public class Organization extends BaseModel {
	private static final long serialVersionUID = 1923972903142555938L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@In
	@DocumentId
	private Long pkOrganization;

	/** 申请编码 */
	@Field
	@Column
	private String code;

	/** 机构性质 */
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private OrgOwnership orgOwnership;

	/** 营业执照 */
	@Field
	@Column
	private String businessLicence;

	/** 执照照片 */
	@Field
	@Column
	private String licencePhoto;

	/** 机构成立日期 */
	@Column
	private Date createDate;

	/** 营业期限开始时间 */
	@Column
	private Date businessStartDate;

	/** 营业期限结束时间 */
	@Column
	private Date businessEndDate;

	/** 营业执照地址 省/市/区（县） */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkBusinessAddress")
	@IndexedEmbedded
	private AdministrativeDivision businessAddress;

	/** 营业执照地址 乡（镇）/街道/村 */
	@Column
	private String businessStreet;

	/** 注册资本 （万元） */
	@Column
	private Integer registereCapital;

	/** 经营范围 */
	@Column(length = 1023)
	private String businessScope;

	/** 业务类型 */
	@OneToMany(mappedBy = "organization", cascade = CascadeType.ALL)
	private Set<OrganizationBusinessType> businessTypes;

	/** 企业LOGO */
	@Field
	@Column
	private String logo;

	/** 公司所在地 省/市/区（县） */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkRegisterAddress")
	@IndexedEmbedded
	private AdministrativeDivision registerAddress;

	/** 银行认证信息信息 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkBankPermission")
	private BankPermission bankPermission;

	/** 组织代码 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOrganizationCode")
	private OrganizationCode organizationCode;

	/** 税务信息 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkTaxRegister")
	private TaxRegister taxRegister;

	/** 公司所在地 乡（镇）/街道/村 */
	@Column
	@Field
	private String street;

	/** 企业服务介绍 */
	@Column
	@Field
	private String introduces;

	/** 企业公函 */
	@Column
	@Field
	private String thepublic;

	/** 办公电话 */
	@Column
	@Field
	private String phone;

	/** 管理员身份证照 */
	@Column
	@Field
	private String id;

	/** 审核次数 */
	@Column
	@Field
	private Integer count;

	/** 开户银行 */
	@Field
	@Column
	private String depositBank;

	/** 银行账号 */
	@Field
	@Column
	private String bankCardNumber;

	/** 机构名称 */
	@Column(length = 30, unique = true, nullable = false)
	@Field
	private String name;

	/** 法人 */
	@Column(length = 30)
	@Field
	private String legalRepresentative;

	/** 法人证件类型 */
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private CorporationIdType corporationCardType;

	/** 法人证件 */
	@Field
	@Column
	private String corporationCard;

	/** 法人证件照 */
	@Field
	@Column
	private String corporationCardPhoto;

	/** 简介 */
	@Field
	@Column(length = 6000)
	private String introduction;

	/** 状态 */
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private Status status;

	/** 机构类型 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private Type type;

	/** 启用时间 */
	@Column
	@Field
	@Between
	private Date enableTime;

	/** 停用时间 */
	@Column
	@Field
	@Between
	private Date disableTime;

	/** 最大服务点数量 */
	@Field
	@Column
	private Integer maxServPointNum;

	/** 创建时间 */
	@Column
	@Field
	@Between
	private Date createTime;

	/** 创建人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkCreateUser")
	@IndexedEmbedded
	private User createUser;

	/** 邮编 */
	@Column(length = 30)
	@Field
	private String zipCode;

	/** 联系人1姓名 */
	@Column(length = 30)
	@Field
	private String contact1Name;

	/** 联系人1电话 */
	@Column(length = 30)
	@Field
	private String contact1Phone;

	/** 联系人1Email */
	@Column(length = 30)
	@Field
	private String contact1Email;

	/** 联系人1地址 */
	@Column(length = 255)
	@Field
	private String contact1Address;

	/** 联系人1邮编 */
	@Column(length = 30)
	@Field
	private String contact1ZipCode;

	/** 联系人2姓名 */
	@Column(length = 30)
	@Field
	private String contact2Name;

	/** 联系人2电话 */
	@Column(length = 30)
	@Field
	private String contact2Phone;

	/** 联系人2Email */
	@Column(length = 30)
	@Field
	private String contact2Email;

	/** 联系人2地址 */
	@Column(length = 255)
	@Field
	private String contact2Address;

	/** 联系人2邮编 */
	@Column(length = 30)
	@Field
	private String contact2ZipCode;
	
	/**
	 * 是否推荐
	 */
	@Column(length = 30)
	@Field
	private IsRecommend IsRecommend;

	@Version
	private Integer version;

	@JsonSerialize(using = EnumSerializer.class)
	public static enum OrgOwnership {
		State("公办"), Civilian("民办");

		private String display;

		OrgOwnership(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum IsRecommend {
		YES("推荐"), NO("不推荐");

		private String display;

		IsRecommend(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	/**
	 * 法人证件类型
	 * 
	 * @author
	 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum CorporationIdType {
		IdentityCard("身份证"), MilitaryID("军官证"), Passport("护照");

		private String display;

		CorporationIdType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	/**
	 * 状态
	 * 
	 * @author
	 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Status {
		Setting("启用"), BlockUp("停用");

		private String display;

		Status(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	/**
	 * 机构类型
	 * 
	 * @author
	 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Type {
		Common("运营机构"), Government("政府"), Provider("服务商");

		private String display;

		Type(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getPkOrganization() {
		return pkOrganization;
	}

	public void setPkOrganization(Long pkOrganization) {
		this.pkOrganization = pkOrganization;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLegalRepresentative() {
		return legalRepresentative;
	}

	public void setLegalRepresentative(String legalRepresentative) {
		this.legalRepresentative = legalRepresentative;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	public String getContact1Name() {
		return contact1Name;
	}

	public void setContact1Name(String contact1Name) {
		this.contact1Name = contact1Name;
	}

	public String getContact1Phone() {
		return contact1Phone;
	}

	public void setContact1Phone(String contact1Phone) {
		this.contact1Phone = contact1Phone;
	}

	public String getContact1Email() {
		return contact1Email;
	}

	public void setContact1Email(String contact1Email) {
		this.contact1Email = contact1Email;
	}

	public String getContact1Address() {
		return contact1Address;
	}

	public void setContact1Address(String contact1Address) {
		this.contact1Address = contact1Address;
	}

	public String getContact1ZipCode() {
		return contact1ZipCode;
	}

	public void setContact1ZipCode(String contact1ZipCode) {
		this.contact1ZipCode = contact1ZipCode;
	}

	public String getContact2Name() {
		return contact2Name;
	}

	public void setContact2Name(String contact2Name) {
		this.contact2Name = contact2Name;
	}

	public String getContact2Phone() {
		return contact2Phone;
	}

	public void setContact2Phone(String contact2Phone) {
		this.contact2Phone = contact2Phone;
	}

	public String getContact2Email() {
		return contact2Email;
	}

	public void setContact2Email(String contact2Email) {
		this.contact2Email = contact2Email;
	}

	public String getContact2Address() {
		return contact2Address;
	}

	public void setContact2Address(String contact2Address) {
		this.contact2Address = contact2Address;
	}

	public String getContact2ZipCode() {
		return contact2ZipCode;
	}

	public void setContact2ZipCode(String contact2ZipCode) {
		this.contact2ZipCode = contact2ZipCode;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getCode() {
		return code;
	}

	public Date getBusinessStartDate() {
		return businessStartDate;
	}

	public void setBusinessStartDate(Date businessStartDate) {
		this.businessStartDate = businessStartDate;
	}

	public Date getBusinessEndDate() {
		return businessEndDate;
	}

	public void setBusinessEndDate(Date businessEndDate) {
		this.businessEndDate = businessEndDate;
	}

	public AdministrativeDivision getBusinessAddress() {
		return businessAddress;
	}

	public void setBusinessAddress(AdministrativeDivision businessAddress) {
		this.businessAddress = businessAddress;
	}

	public String getBusinessStreet() {
		return businessStreet;
	}

	public void setBusinessStreet(String businessStreet) {
		this.businessStreet = businessStreet;
	}

	public Integer getRegistereCapital() {
		return registereCapital;
	}

	public void setRegistereCapital(Integer registereCapital) {
		this.registereCapital = registereCapital;
	}

	public String getBusinessScope() {
		return businessScope;
	}

	public void setBusinessScope(String businessScope) {
		this.businessScope = businessScope;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public OrgOwnership getOrgOwnership() {
		return orgOwnership;
	}

	public void setOrgOwnership(OrgOwnership orgOwnership) {
		this.orgOwnership = orgOwnership;
	}

	public String getBusinessLicence() {
		return businessLicence;
	}

	public void setBusinessLicence(String businessLicence) {
		this.businessLicence = businessLicence;
	}

	public String getLicencePhoto() {
		return licencePhoto;
	}

	public void setLicencePhoto(String licencePhoto) {
		this.licencePhoto = licencePhoto;
	}

	public AdministrativeDivision getRegisterAddress() {
		return registerAddress;
	}

	public void setRegisterAddress(AdministrativeDivision registerAddress) {
		this.registerAddress = registerAddress;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getDepositBank() {
		return depositBank;
	}

	public void setDepositBank(String depositBank) {
		this.depositBank = depositBank;
	}

	public String getBankCardNumber() {
		return bankCardNumber;
	}

	public void setBankCardNumber(String bankCardNumber) {
		this.bankCardNumber = bankCardNumber;
	}

	public CorporationIdType getCorporationCardType() {
		return corporationCardType;
	}

	public void setCorporationCardType(CorporationIdType corporationCardType) {
		this.corporationCardType = corporationCardType;
	}

	public String getCorporationCard() {
		return corporationCard;
	}

	public void setCorporationCard(String corporationCard) {
		this.corporationCard = corporationCard;
	}

	public String getCorporationCardPhoto() {
		return corporationCardPhoto;
	}

	public void setCorporationCardPhoto(String corporationCardPhoto) {
		this.corporationCardPhoto = corporationCardPhoto;
	}

	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Date getEnableTime() {
		return enableTime;
	}

	public void setEnableTime(Date enableTime) {
		this.enableTime = enableTime;
	}

	public Date getDisableTime() {
		return disableTime;
	}

	public void setDisableTime(Date disableTime) {
		this.disableTime = disableTime;
	}

	public Integer getMaxServPointNum() {
		return maxServPointNum;
	}

	public void setMaxServPointNum(Integer maxServPointNum) {
		this.maxServPointNum = maxServPointNum;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	public String getLogo() {
		return logo;
	}

	public void setLogo(String logo) {
		this.logo = logo;
	}

	public String getIntroduces() {
		return introduces;
	}

	public BankPermission getBankPermission() {
		return bankPermission;
	}

	public void setBankPermission(BankPermission bankPermission) {
		this.bankPermission = bankPermission;
	}

	public OrganizationCode getOrganizationCode() {
		return organizationCode;
	}

	public void setOrganizationCode(OrganizationCode organizationCode) {
		this.organizationCode = organizationCode;
	}

	public TaxRegister getTaxRegister() {
		return taxRegister;
	}

	public void setTaxRegister(TaxRegister taxRegister) {
		this.taxRegister = taxRegister;
	}

	public void setIntroduces(String introduces) {
		this.introduces = introduces;
	}

	public String getThepublic() {
		return thepublic;
	}

	public void setThepublic(String thepublic) {
		this.thepublic = thepublic;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Set<OrganizationBusinessType> getBusinessTypes() {
		return businessTypes;
	}

	public void setBusinessTypes(Set<OrganizationBusinessType> businessTypes) {
		this.businessTypes = businessTypes;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

}
